//
//  ViewController.m
//  Picture
//
//  Created by Justsoso on 16/2/29.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
@property (weak,nonatomic) UIScrollView *scrollView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 375, 200)];
    for(int i=0;i<6;i++)
    {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(375*i, 0, 375, 200)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%i",i+1]];
        [scrollView addSubview:imageView];
    }
    
    // 内容尺寸
    scrollView.contentSize = CGSizeMake(375*6, 0);
    // 是否反弹
    scrollView.bounces = NO;
    // 是否显示滑动条
    scrollView.showsHorizontalScrollIndicator = NO;
    // 分页
    scrollView.pagingEnabled = YES;
    scrollView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:scrollView];
    
    scrollView.delegate = self;
    
    [self.view addSubview:self.pageControl];
    self.pageControl.numberOfPages = 6;
    self.pageControl.pageIndicatorTintColor = [UIColor yellowColor];
    self.pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    
//    self.pageControl.currentPage = scrollView.contentOffset.x/375;
//}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.pageControl.currentPage = scrollView.contentOffset.x/375;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
